<template>
  <div class="search-page">
    <SearchResultToolBar :search="search" />
    <div v-for="(info,i) in searchResultList"
         :key="i">
      <SearchResultItem :info="info" />
    </div>
  </div>
</template>

<script>
import SearchResultToolBar from '@/components/SearchResultToolBar.vue'
import SearchResultItem from '@/components/SearchResultItem.vue'
import DB from "@/data/search.json"

export default {
  components: {
    SearchResultToolBar,
    SearchResultItem
  },
  data () {
    return {
      searchResultList: []
    }
  },
  computed: {
    search () {
      return this.$router.history.current.params.searchText
    }
  },
  created () {
    this.doSearchResult()
  },
  beforeRouteUpdate (to, from, next) {
    next()
    this.doSearchResult()
  },
  methods: {
    doSearchResult () {
      const search = this.$router.history.current.params.searchText
      if (DB.hasOwnProperty(search)) {
        this.searchResultList = DB[search]
      } else {
        this.searchResultList = []
      }
    }
  }
}
</script>

<style lang="less" scoped>
</style>
